﻿using System;

namespace IQIGame.Onigao.GamePlay
{
    using static AuidoSourceType;
    using static GameQualityType;
    using static OpenStateType;
    using static StoryPlaySpeedType;

    public struct SettingGameData : IEquatable<SettingGameData>
    {
        public GameQualityType quality;
        public OpenStateType highFrame;
        public BigSkillPlayModelType bigSkillPlayModel;
        public OpenStateType storyDefaultName;
        public OpenStateType storyAutoPlay;
        public StoryPlaySpeedType storyPlaySpeed;

        public override int GetHashCode()
        {
            return HashCode.Combine(quality.GetHashCode(), highFrame.GetHashCode(), bigSkillPlayModel.GetHashCode(), storyDefaultName.GetHashCode(), storyAutoPlay.GetHashCode(), storyPlaySpeed.GetHashCode());
        }

        public override bool Equals(object obj)
        {
            if (obj is SettingGameData other)
                return Equals(other);
            return false;
        }

        public bool Equals(SettingGameData other)
        {
            return quality == other.quality && highFrame == other.highFrame &&
                bigSkillPlayModel == other.bigSkillPlayModel && storyDefaultName == other.storyDefaultName &&
                storyAutoPlay == other.storyAutoPlay && storyPlaySpeed == other.storyPlaySpeed;
        }

        private SettingGameData Reset()
        {
            quality = Medium;
            highFrame = Open;
            bigSkillPlayModel = BigSkillPlayModelType.EveryTime;
            storyDefaultName = Open;
            storyAutoPlay = Open;
            storyPlaySpeed = Normal;
            return this;
        }

        public void Set(Tuple<int, int, int, int, int, int> data)
        {
            quality = data.Item1 >= 0 ? (GameQualityType)data.Item1 : quality;
            highFrame = data.Item2 >= 0 ? (OpenStateType)data.Item2 : highFrame;
            bigSkillPlayModel = data.Item3 >= 0 ? (BigSkillPlayModelType)data.Item3 : bigSkillPlayModel;
            storyDefaultName = data.Item4 >= 0 ? (OpenStateType)data.Item4 : storyDefaultName;
            storyAutoPlay = data.Item5 >= 0 ? (OpenStateType)data.Item5 : storyAutoPlay;
            storyPlaySpeed = data.Item6 >= 0 ? (StoryPlaySpeedType)data.Item6 : storyPlaySpeed;
        }

        static public bool operator ==(SettingGameData lhs, SettingGameData rhs)
        {
            return lhs.Equals(rhs);
        }

        static public bool operator !=(SettingGameData lhs, SettingGameData rhs)
        {
            return !(lhs == rhs);
        }

        static readonly public SettingGameData Default = new SettingGameData().Reset();
    }

    public struct SettingAudioData : IEquatable<SettingAudioData>
    {
        public int bgm;
        public int sfx;
        public int voice;
        public AuidoSourceType auidoSource;

        public override int GetHashCode()
        {
            return HashCode.Combine(bgm.GetHashCode(), sfx.GetHashCode(), voice.GetHashCode(), auidoSource.GetHashCode());
        }

        public override bool Equals(object obj)
        {
            if (obj is SettingAudioData other)
                return Equals(other);
            return false;
        }

        public bool Equals(SettingAudioData other)
        {
            return bgm == other.bgm && sfx == other.sfx &&
                voice == other.voice && auidoSource == other.auidoSource;
        }

        private SettingAudioData Reset()
        {
            bgm = 100;
            sfx = 100;
            voice = 100;
            auidoSource = Chinese;
            return this;
        }

        public void Set(Tuple<int, int, int, int> data)
        {
            bgm = data.Item1;
            sfx = data.Item2;
            voice = data.Item3;
            auidoSource = data.Item4 >= 0 ? (AuidoSourceType)data.Item4 : auidoSource;
        }

        static public bool operator ==(SettingAudioData lhs, SettingAudioData rhs)
        {
            return lhs.Equals(rhs);
        }

        static public bool operator !=(SettingAudioData lhs, SettingAudioData rhs)
        {
            return !(lhs == rhs);
        }

        static readonly public SettingAudioData Default = new SettingAudioData().Reset();
    }
}
